/**
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-03 14:14:47
 * Copyright (c) 2015- joysuch-版权所有
 */

package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.BpStorageTank;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.List;

/**
 * BpStorageTankDao
 */
public interface BpStorageTankDao extends JpaRepository<BpStorageTank, Long>, QuerydslPredicateExecutor<BpStorageTank> {
    public Page<BpStorageTank> findAll(Specification<BpStorageTank> spec, Pageable pageable);

    public BpStorageTank save(BpStorageTank bean);

    public void delete(BpStorageTank bean);

    public List<BpStorageTank> findByBpStorageTankArea(Long areaId);

    List<BpStorageTank> findByCode(String code);

    @Query("select count(m) from BpStorageTank m where code=?1 and id != ?2")
    Long countOfCodeExcludeId(String code, Long excludeId);

    @Query("select m from BpStorageTank m where uniCode=?1")
    public BpStorageTank findByUniCode(String uniCode);

    @Query(value = "select * from wwyt_bp_storage_tank where STORAGE_TANK_AREA_ID = ?1 and DELETE_FLAG = '0' ", nativeQuery = true)
    List<BpStorageTank> findByBpStorageTankAreaId(Long id);
}
